<template>
  <div id="add">
    <el-dialog :title="kind == 'add' ? '添加' : '修改'" :visible.sync="dialogFormVisible" :modal-append-to-body="false" :before-close="closeshow" @opened="qx">
      <div v-for="(item, index) in data" :key="index">
        <el-form :model="data">
          <el-form-item :label="index" :label-width="formLabelWidth">
            <el-input v-model="data[index]" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="qx">取 消</el-button>
        <el-button type="primary" @click="what">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapActions, mapMutations, mapGetters } from 'vuex';
export default {
  props: ['dialogFormVisible', 'fromdata', 'theID', 'kind', 'sublist'],
  data() {
    return {
      data: {},
      formLabelWidth: '120px',
    };
  },

  mounted() {},

  methods: {
    ...mapActions(['tongyong']),
    what() {
      if (this.kind == 'add') {
        this.add();
      } else if (this.kind == 'rewriter') {
        this.rewrite();
      }
    },
    async rewrite() {
      this.sublist.quantity = this.data.剂量;
      this.sublist.mediMoney = this.sublist.pay * this.sublist.quantity;
      const res = await this['tongyong']({
        name: 'GET_REWRITERYAO',
        data: this.sublist,
      });
      console.log(res);
      if (res.data.msg == '修改成功') {
        this.$message({
          message: '修改成功',
          type: 'warning',
        });
      } else {
        this.$message({
          message: '不存在此药帐单',
          type: 'warning',
        });
      }

      this.closeshow();
    },
    add() {
      this.closeshow();
    },

    qx() {
      this.data = JSON.parse(JSON.stringify(this.fromdata));
    },

    closeshow() {
      console.log(this.from, this.fromdata);
      this.$emit('close', false);
      this.data = {};
    },
  },
};
</script>
<style scoped>
.el-dialog {
  width: 90%;
}
</style>
